package com.gs.threadpackage;

/**
 * @ProjectName: springbootmybitstest
 * @Package: com.gs.threadpackage
 * @Description: java类作用描述
 * @Author: Administrator
 * @CreateDate: 2018/6/28 11:20
 * @UpdateUser: Administrator
 * @UpdateDate: 2018/6/28 11:20
 * @UpdateRemark: The modified content
 * @Version: 1.0
 **/
public class Clerk {

    private static  int MAX_PRODUCT=20;

    private static  int MIN_PRODUCT =0;

    private int product =0;

    public synchronized void addProduct(){
         if(this.product>=MAX_PRODUCT){
             try {
                 wait();
                 System.out.println("产品已满,请稍候再生产");
             } catch (InterruptedException e) {
                 e.printStackTrace();
             }
              return ;
         }
           this.product++;
        System.out.println("生产者生产了第"+this.product+"个产品");
        notifyAll();

    }

public synchronized void  getProduct(){

  if (this.product<=MIN_PRODUCT){
      try {
          wait();
          System.out.println("产品处于缺货状态");
      } catch (InterruptedException e) {
          e.printStackTrace();
      }
         return ;

  }
    System.out.println("生产者消费了第"+this.product+"个产品");
    this.product--;
    notifyAll();
}







}
